#@layout()

#define script()
<script>
    function showLoading(){
        $('.loading i').attr('class','fas fa-spinner fa-spin');
        $('.loading-text').text('后台正在生成中...');
        $('.loading').show();
    }

    function refreshMessage() {
        setTimeout(function () {
            ajaxGet("#(CPATH)/admin/staticize/message", function (resp) {
                if (resp.loading) {
                    refreshMessage();
                } else {
                    if (resp.isOk) {
                        $('.loading i').attr('class','fas fa-check');
                        $('.loading-text').text('静态页面生成完毕!');
                    } else {
                        $('.loading i').attr('class','fa-solid fa-xmark');
                        $('.loading-text').text(resp.message);
                    }
                }
            })
        }, 1000);
    }

    $("#genIndex").on("click", function () {
        showLoading();
        ajaxGet("#(CPATH)/admin/staticize/doGenIndex", function () {
            refreshMessage();
        }, function (data) {
            alert(data.message);
        })
    })

    $("#genSite").on("click", function () {
        showLoading();
        ajaxGet("#(CPATH)/admin/staticize/doGenSite", function () {
            refreshMessage();
        }, function (data) {
            alert(data.message);
        })
    })

    $("#genAllSite").on("click", function () {
        showLoading();
        ajaxGet("#(CPATH)/admin/staticize/doGenAllSite", function () {
            refreshMessage();
        }, function (data) {
            alert(data.message);
        })
    })

    $("#ftpPublish").on("click", function () {
        ajaxGet("#(CPATH)/admin/staticize/doFtpPublish", function () {
            alert("FTP 发布成功");
        }, function (data) {
            alert(data.message);
        })
    })

    $("#aliyunOssPublish").on("click", function () {
        ajaxGet("#(CPATH)/admin/staticize/doAliyunOssPublish", function () {
            alert("阿里云 OSS 发布成功");
        }, function (data) {
            alert(data.message);
        })
    })

</script>
#end

#define content()

<section class="content-header">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-6">

                <div class="row mb-2">
                    <div class="col-sm-12">
                        <h1>
                            网站静态化设置
                            <small data-toggle="tooltip" title="" data-placement="right"
                                   data-trigger="hover"><i class="nav-icon far fa-question-circle"></i></small>
                            <small> 首页 / 系统 / 网站静态化设置</small>
                        </h1>
                    </div>
                </div>
            </div>
        </div>

    </div><!-- /.container-fluid -->
</section>

<section class="content">

    <div class="container-fluid">
        <div class="card card-outline card-primary">

            <!-- /.card-header -->
            <!-- form start -->
            <form class=" form-setting" autocomplete="off"
                  method="post"
                  id="optionForm">
                <div class="card-body">

                    <div class="alert alert-info alert-dismissible" style="background-color: #047bff;
    border-color: #0067d8;">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> 静态化功能描述 </h5>
                        通过 JPress 的静态化功能，可以把网站内容生成静态的 html 资源文件，通过 Nginx 等第三方静态服务器，浏览生成的内容。<br/>
                        这样的好处是：理论上提高了网站安全性以及访问速度，在一些极特殊的场景下可以使用这种方案进行网站部署；但因为静态化的原因，也带来了功能的缺失：比如不能评论、无法搜索、不能记录网站访问量等。
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">开启静态化功能</label>
                        <div class="col-sm-6">
                            <input type="checkbox" class="switchery" data-for="staticize_enable"
                                   #checkedIf(option("staticize_enable"))>
                            <input type="hidden" id="staticize_enable" name="staticize_enable">
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">静态页面存放路径</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="例如：/www/nginx/web"
                                   name="staticize_path"
                                   value="#option('staticize_path')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label"></label>

                        <div class="col-sm-6">
                            <button type="button" class="btn btn-default" style="margin-top: 5px"
                                    id="genIndex"><i class="fas fa-home"></i> 重新生成首页（当前站点）
                            </button>

                            <button type="button" class="btn btn-default" style="margin-top: 5px"
                                    id="genSite"><i class="fas fa-network-wired"></i> 全部页面生成（当前站点）
                            </button>
                            <button type="button" class="btn btn-default" style="margin-top: 5px"
                                    id="genAllSite"><i class="fas fa-undo"></i> 全部站点生成
                            </button>
                        </div>
                    </div>


                    <div class="form-group row loading" style="display: none">
                        <label class="col-sm-2 col-form-label"></label>

                        <div class="col-sm-6">
                            <div style="background: #ccc;padding: 5px">
                                <i class="fas fa-spinner fa-spin"></i> <span class="loading-text">后台正在生成中...</span>
                            </div>

                        </div>
                    </div>

                    <h4 class="form-header">FTP 文件发布</h4>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">FTP 服务器</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="请填写服务器 IP 地址 ..."
                                   name="staticize_ftp_host"
                                   value="#option('staticize_ftp_host')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">FTP 端口号</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="请填写服务器 FTP 端口号 ..."
                                   name="staticize_ftp_port"
                                   value="#option('staticize_ftp_port')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">FTP 服务器路径</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="请填写服务器 FTP 服务器路径 ..."
                                   name="staticize_ftp_server_path"
                                   value="#option('staticize_ftp_server_path')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">FTP 账号</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="请填写服务器 FTP 账号 ..."
                                   name="staticize_ftp_username"
                                   value="#option('staticize_ftp_username')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">FTP 密码</label>
                        <div class="col-sm-6">
                            <input type="password" class="form-control" autocomplete="new-password"
                                   placeholder="请填写服务器 FTP 密码 ..."
                                   name="staticize_ftp_password"
                                   value="#option('staticize_ftp_password')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-default" style="margin-top: 5px"
                                    id="ftpPublish"><i class="fas fa-plane-departure"></i> 一键发布 FTP 服务器
                            </button>
                        </div>
                    </div>


                    <h4 class="form-header">阿里云 OSS 发布</h4>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">API 访问域名</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="阿里云oss的 endPoint"
                                   name="staticize_aliyunoss_endpoint" value="#option('staticize_aliyunoss_endpoint')">
                            <p class="text-muted"> 阿里云API域名详情：<a target="_blank"
                                                                 href="https://help.aliyun.com/document_detail/31837.html">https://help.aliyun.com/document_detail/31837.html</a>。
                            </p>

                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">AccessKeyId</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="通过阿里云安全令牌生成..."
                                   name="staticize_aliyunoss_accesskeyid"
                                   value="#option('staticize_aliyunoss_accesskeyid')">
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">AccessKeySecret</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="通过阿里云安全令牌生成..."
                                   name="staticize_aliyunoss_accesskeysecret"
                                   value="#option('staticize_aliyunoss_accesskeysecret')">
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">存储空间</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="阿里云oss的 bucketName"
                                   name="staticize_aliyunoss_bucketname"
                                   value="#option('staticize_aliyunoss_bucketname')">
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-default" style="margin-top: 5px"
                                    id="aliyunOssPublish"><i class="fas fa-plane-departure"></i> 一键发布到 OSS
                            </button>
                        </div>
                    </div>


                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                    <div class="offset-sm-2 col-sm-10 submit-block">
                        <div class="card-submit">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </div>
                </div>
                <!-- /.card-footer -->
            </form>
        </div>
    </div>
    </div>

</section>

#end
